/*
 * BncsAuthInfoServer.h
 *
 *  Created on: Nov 20, 2008
 *      Author: nathan
 */

#ifndef BNCSAUTHINFOSERVER_H_
#define BNCSAUTHINFOSERVER_H_

#include "BncsMessage.h"
#include "BncsMessageFactory.h"

class BncsAuthInfoServerData : public QSharedData
{
public:
	quint32 logonType;
	quint32 serverToken;
	quint32 udpValue;
	quint32 mpqFileTime[2];
	QByteArray IX86FileName;
	QByteArray valueString;
	quint8 serverSignature[128];
};

class BncsAuthInfoServer : public BncsMessage
{
	BNCS_MESSAGE_REGISTER(BncsAuthInfoServer, 0x50);

public:
	QSharedDataPointer<BncsAuthInfoServerData> d;

public:
	quint32 id()
	{
		return id;
	}

	int size()
	{
		return sizeof(d->logonType) + sizeof(d->serverToken) + sizeof(d->udpValue) +
		       sizeof(d->mpqFileTime) + (d->IX86FileName.size() + 1) + (d->valueString.size() + 1) +
		       sizeof(d->serverSignature);
	}

	void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->logonType;
		ds >> d->serverToken;
		ds >> d->udpValue;
		ds >> d->mpqFileTime[0];
		ds >> d->mpqFileTime[1];
		d->IX86FileName = readStringFrom(ds);
		d->valueString = readStringFrom(ds);
		ds.readRawData((char*)d->serverSignature, sizeof(d->serverSignature));

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << d->logonType;
		ds << d->serverToken;
		ds << d->udpValue;
		ds << d->mpqFileTime[0];
		ds << d->mpqFileTime[1];
		writeStringTo(ds, d->IX86FileName);
		writeStringTo(ds, d->valueString);
		ds.writeRawData((char*)d->serverSignature, sizeof(d->serverSignature));

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

#endif /* BNCSAUTHINFOSERVER_H_ */
